﻿$(document).ready(function(){

	/*- select-city__link -*/
	$('.select-city__link').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});

	/*- contact-info -*/
	$('.contact-info address').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});
	
	/*- shopping-cart -*/
	$('.shopping-cart__link').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});
	
	/*- drop-down-menu -*/
	$('.drop-down-menu__title').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});
	
	/*- drop-down-menu__list__tabs -*/
	$(function(){
		$('.drop-down-menu__list__tabs__title').click(function(){
			$(this)
				.siblings().removeClass('selected').end()
				.next('.drop-down-menu__list__tabs__content').andSelf().addClass('selected');
		});
	});
	
	/*- drop-down-menu__list -*/
	$('.drop-down-menu__list__link').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$('.drop-down-menu__list__item').removeClass('selected');
			$(this).parent().addClass('selected');
		}
		return false;
	});
	
	/*- info-tabs -*/
	$(function(){
		$('.info-tabs__title').click(function(){
			$(this)
				.siblings().removeClass('selected').end()
				.next('.info-tabs__content').andSelf().addClass('selected');
		});
	});
	
	/*- goods-tabs -*/
	$(function(){
		$('.goods-tabs__title').click(function(){
			$(this)
				.siblings().removeClass('selected').end()
				.next('.goods-tabs__content').andSelf().addClass('selected');
            $(".goods__list").removeClass('list');
            $('.goods__lists').removeClass('selected');
            $('.goods__blocks').addClass('selected');
		});
	});
	
	/*- goods -*/
	$('.goods__lists').click(function () {
		var parent = $(this).parents('.goods');
		$('.goods__blocks',parent).removeClass('selected');
		$(this).addClass('selected');
		$(".goods__list").addClass('list');
	});
	$('.goods__blocks').click(function () {
		var parent = $(this).parents('.goods');
		$('.goods__lists',parent).removeClass('selected');
		$(this).addClass('selected');
		$('.goods__list').removeClass('list');
    });
	
	/*- promo-slider__inner -*/
	$(".promo-slider__inner").sliderkit({
		auto:true,
		autospeed:5000,
		tabs:true,
		freeheight:true,
		circular:true,
		panelfx:"none"
	});
	
	/*- filter-goods__content .closed -*/
	$('.filter-goods__content .closed dt').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});
	
	/*- price -*/
	jQuery("#price").slider({
	min: 0,
	max: 100000,
	values: [0,100000],
	range: true,
	stop: function(event, ui) {
		jQuery("#price__min-cost").val(jQuery("#price").slider("values",0));
		jQuery("#price__max-cost").val(jQuery("#price").slider("values",1));
		
    },
    slide: function(event, ui){
		jQuery("#price__min-cost").val(jQuery("#price").slider("values",0));
		jQuery("#price__max-cost").val(jQuery("#price").slider("values",1));
    }
	});

	jQuery("input#price__min-cost").change(function(){

		var value1=jQuery("#price__min-cost").val();
		var value2=jQuery("#price__max-cost").val();

		if(parseInt(value1) > parseInt(value2)){
			value1 = value2;
			jQuery("#price__min-cost").val(value1);
		}
		jQuery("#price").slider("values",0,value1);	
	});

		
	jQuery("#price__max-cost").change(function(){
			
		var value1=jQuery("#price__min-cost").val();
		var value2=jQuery("#price__max-cost").val();
		
		if (value2 > 100000) { value2 = 100000; jQuery("input#price__max-cost").val(100000)}

		if(parseInt(value1) > parseInt(value2)){
			value2 = value1;
			jQuery("#price__max-cost").val(value2);
		}
		jQuery("#price").slider("values",1,value2);
	});

	jQuery('#price input').keypress(function(event){
		var key, keyChar;
		if(!event) var event = window.event;
		
		if (event.keyCode) key = event.keyCode;
		else if(event.which) key = event.which;
	
		if(key==null || key==0 || key==8 || key==13 || key==9 || key==46 || key==37 || key==39 ) return true;
		keyChar=String.fromCharCode(key);
		
		if(!/\d/.test(keyChar))	return false;
	
	});
	
	/*- b-core-ui-select__select -*/	
	$(window).load(function () {	
	
		$('.b-core-ui-select__select').coreUISelect({
			onInit : addCoreUISelectListener,
			onOpen : addCoreUISelectListener,
			onClose : addCoreUISelectListener,
			onChange : addCoreUISelectListener,
			onDestroy : addCoreUISelectListener
		});

		function addCoreUISelectListener(select, event){
			console.log(select, event);
		}
		
	});	
	
	/*- vacancies -*/
	$('.vacancies__link').click(function(e) {
		
		if($(this).parent().hasClass('selected')) {
			$(this).parent().removeClass('selected');
		} else {
			$(this).parent().addClass('selected');
		}
	});
	
	/*- popup -*/
	var popupParams, popupSelect, docHeight, citySelect, mapCanvas, mapLatlng, markerTitle, infoWindowContent, popupTitle, gmapCords, radioSelected;

	$('.show-popup').click(function(){
		popupParams = $(this).attr('href');
		popupSelect = $(popupParams);
		getPopup('show', this);
		return false;
	});

	$('.global-popup__close, .global-popup__popup-overlay').click(function(){
		getPopup('hide', this);
		return false;
	});

	function getPopup(action, el){
		if(action == 'show') {
			popupSelect.fadeIn(100);
		} else {
			popupSelect.fadeOut(100);
		}
		
	}
	
	/*- product-info__slider -*/
	$(".product-info__slider").sliderkit({
		shownavitems:3,
		circular:true,
		navitemshover:false,
		panelfxspeed:400,
		auto:false,
		autostill:false
	});
	
	/*- scroll-simple -*/
    $('.scroll-simple').scrollbar({
        "type": "simple"
    });
	
	$(function(){
		$('.social-tabs__title').click(function(){
			$(this)
				.siblings().removeClass('selected').end()
				.next('.social-tabs__content').andSelf().addClass('selected');
		});
	});

});









